$(function(){
    var arry=[];
    $(".pathLeft  li").each(function () {
        if ($(this).index() == 1) {
            $(this).find('a').addClass("select");
        } else {
            $(this).find('a').removeClass("select");
        }
    });
    template.helper('href', function (num) {
        if (num != "") {
            return '' + bath + num;
        } else {
            return 'javascript:;';
        }
    });
    template.helper('courseTypeVar', function (num) {
        var courseType = num;
        if (courseType=="直播"){
            courseType=(courseType=="直播")?0:1;//0：直播 1：点播
        }
        else{
            courseType=(courseType=="true")?0:1;//0：直播 1：点播
        }
        return courseType;
    });
    template.helper('heima', function (online_course,num) {
        var courseType = num;
        if (online_course==0){
            return ""
        }
    });
//	遍历左侧边栏数据
    var vocatTabla=
        "<ul class='btn-item'>"+
        "{{each menu as $value}}"+
        "<a href='#'><li data-id='{{$value.id}}' >"+
        "<span data-id='{{$value.id}}' title='{{$value.protype_name}}'>{{$value.protype_name}}</span>"+
        "</li></a>"+
        "{{/each}}"+
        "</ul>";
//  遍历右边数据
    var vocatList = "{{each data as w}}" +
        "<div class='vocatList' id='{{w.id}}'>"+
        "<div style='float:left;width: 295px;height:183px;overflow:hidden;'>"+
        "{{#indexHref(w.type,w.id)}}<div class='vocatImage'>{{#hasImg(w.banner_img)}}</div></a></div>"+
        "<div class='vocatListBody'>"+
        "<div class='vocatContentShow'>"+
        "<p class='vocatListTitle' title='{{w.course_name}}'>"+
        "{{#indexHref(w.type,w.id)}}{{w.course_name}}</a></p>"+
        "<p class='vocatListText dot5' title='{{w.course_detail}}'>{{w.course_detail}}</p>"+
        "<div class='second_div'>"+
        "<div class='offlinStu'>"+
        "<div class='pop_style'>"+
        "<img src='/home/img/online_pop.png'/>"+
        "</div>"+
        "{{#indexHref(w.type,w.id)}}"+
        "在线观看</a>"+
        "</div>"+
        "</div>"+
        "</div>"+
        "</div>"+
        "<div class='vocatListRight' data-id={{w.id}}>"+
        "<p class='vocatListRightTitle'><img src='/home/img/dataEarth.png'/><span>视频数据</span></p>"+
        "<div class='vocatListRightText'>"+
        "<div class='vocatNo1'>"+
        "<div class='stu_pay'>"+
        "<span class='studynum'>点击量</span>"+
        "<span class='payroll'>评论量</span>"+
        "</div>"+
        "<div class='num_show'>"+
        "{{if w.click_num ==null || w.click_num ==''}}"+
        "<span class='studynumShow'>0</span>"+
        "{{else}}"+
        "<span class='studynumShow'>{{w.click_num}}</span>"+
        "{{/if}}"+
        "<div class='salary_show'>"+
        "{{if w.comment_num ==null || w.comment_num ==''}}"+
        "<span class='payrollShow'>0</span>"+
        "{{else}}"+
        "<span class='payrollShow'>{{w.comment_num}}K</span>"+
        "{{/if}}"+
        "</div>"+
        "</div>"+
        "</div>"+
        "<div class='vocatNo2'>"+
        "<div class='stu_pay'>"+
        "<span class='studynum'>点赞数</span>"+
        "<span class='payroll'>搜索量</span>"+
        "</div>"+
        "<div class='num_show'>"+
        "<span class='studynumShow'>{{w.fabulous_num}}</span>"+
        "{{if w.search_num ==null || w.search_num =='0' || w.search_num ==''}}"+
        "<span class='payrollShow'>0</span>"+
        "{{else}}"+
        "<span class='payrollShow'>{{w.search_num}}</span>"+
        "{{/if}}"+
        "</div>"+
        "</div>"+
        "</div>"+
        "<hr class='hr_style'/>"+
        "<div class='show_content'>数据来自<a href='javascript:void(0);' target='_blank'>零玖一</a></div>"+
        "</div>"+
        "</div>"+
        "{{/each}}";
    var kongbai = "<div class='kongbai'>" +
        "<img src='/home/img/empty.png'/>" +
        "<p>暂无数据</p>" +
        "</div>";
    var loading = '<div id="pgbtn" class="pgbtn">'+
        '<a class="bm_h" href="javascript:;"  id="autopbn" ><i></i>加载更多</a>'+
        '</div>';
    //获取课程表列表
    RequestService("/course/getDirectionsNav", "GET", {
        courseType:'all',
    }, function (data) {
        if (data.success === true) {
            $(".vacationalTabal").html(template.compile(vocatTabla)({menu: data.resultObject}));
            getProfessionCourses(data.resultObject[0].id);
            $(".btn-item li").eq(0).addClass("select");
            $(".vacationalTabal .btn-item li").each(function () {
                arry.push($(this).attr("data-id"));
            });
        }else {
            $(".vocationalBody").html(template.compile(kongbai));
        };
    });
    $(document).on('click',".vacationalTabal .btn-item li",function(){
        var pid = $(this).attr("data-id");
        getProfessionCourses(pid,1);
    });
    function getProfessionCourses(pid,p){
        RequestService("/course/getProfessionCourses", "GET",{pid:pid,p:p}, function (result) { //点击学科遍历右侧列表
            if (result.success === true) {
                if(result.page.currentPage == 1 && result.page.currentPage < result.page.totalPageCount){
                    $(".vacationalList").html(template.compile(vocatList)({data: result.resultObject}));
                    $(".vacationalList").append(loading);
                }else if(result.page.currentPage == 1 && result.page.currentPage == result.page.totalPageCount){
                    $(".vacationalList").html(template.compile(vocatList)({data: result.resultObject}));
                }else if(result.page.currentPage != 1 && result.page.currentPage < result.page.totalPageCount){
                    $('#pgbtn').remove();
                    $(".vacationalList").append(template.compile(vocatList)({data: result.resultObject}));
                    $(".vacationalList").append(loading);
                }else if(result.page.currentPage >= result.page.totalPageCount){
                    $('#autopbn').html('没有更多了...');
                }
                $('#autopbn').click(function(){
                    if($(this).html == '没有更多了...'){
                        return false;
                    }else{
                        getProfessionCourses(pid,Number(result.page.currentPage) + 1);
                    }
                });
                var init_id="";
                $(".vocatList").eq(0).each(function () {
                    init_id=$(this).attr("id");
                });
                for(var j=0;j<arry.length;j++){
                    if (parseInt(arry[j])==parseInt(init_id)){
                        $(".btn-item li").removeClass("select");
                        $(".btn-item li").eq(j).addClass("select");

                    };
                };
                $(".offlinStu").hover(function(){
                    $(this).find(".pop_style").show();
                },function(){
                    $(this).find(".pop_style").hide();
                })
                var $dot5 = $('.dot5');
                $dot5.each(function () {
                    if ($(this).height() > 60) {
                        $(this).attr("data-txt", $(this).attr("data-text"));
                        $(this).height(60);
                    }
                    var $dot4 = $(this);
                    function createDots() {
                        $dot4.dotdotdot({
                            after: 'span.qq'
                        });
                    }
                    function destroyDots() {
                        $dot4.trigger('destroy');
                    }
                    createDots();
                    $dot4.on(
                        'click',
                        'a.toggle',
                        function () {
                            $dot4.toggleClass('opened');
                            if ($dot4.hasClass('opened')) {
                                destroyDots();
                            } else {
                                createDots();
                            }
                            return false;
                        }
                    );
                });
                $(".btn-item li").unbind().bind("click",function(){
                    $(".btn-item li").removeClass("select");
                    $(this).addClass("select");

                })
            }else {
                $(".vacationalList").html(kongbai);
            };
        });
    }

});